import { http } from '@/utils/http.ts'
import type {
  OrderCreateParams,
  OrderListResult,
  OrderLogisticResult,
  OrderPreResult,
  OrderResult,
} from '@/types/order'
import type { pageResult } from '@/types/global'

// 获取预付订单
export const getPreOrderApi = () => {
  return http<OrderPreResult>({
    url: '/member/order/pre',
    method: 'GET',
  })
}

// 获取立即购买订单
export const submitOrderApi = (data: { skuId: string; count: number; addressId?: string }) => {
  return http<OrderPreResult>({
    url: '/member/order/pre/now',
    method: 'GET',
    data,
  })
}

// 提交订单
export const submitOrderConfirmApi = (data: OrderCreateParams) => {
  return http<{ id: string }>({
    url: '/member/order',
    method: 'POST',
    data,
  })
}

// 获取订单详情
export const getOrderDetailApi = (id: string) => {
  return http<OrderResult>({
    url: `/member/order/${id}`,
    method: 'GET',
  })
}

// 获取再次购买订单
export const getOrderDetailForReorderApi = (id: string) => {
  return http<OrderPreResult>({
    url: `/member/order/repurchase/${id}`,
    method: 'GET',
  })
}

// 模拟发货
export const mockDeliveryApi = (id: string) => {
  return http({
    url: `/member/order/consignment/${id}`,
    method: 'GET',
  })
}


// 确认收货
export const confirmReceiptApi = (id: string) => {
  return http<OrderResult>({
    url: `/member/order/${id}/receipt`,
    method: 'PUT',
  })
}

// 获取订单物流
export const getOrderLogisticApi = (id: string) => {
  return http<OrderLogisticResult>({
    url: `/member/order/${id}/logistics`,
    method: 'GET',
  })
}

// 删除订单
export const deleteOrderApi = (ids: string[]) => {
  return http({
    url: `/member/order`,
    method: 'DELETE',
    data: {
      ids,
    },
  })
}

// 获取订单列表
export const getOrderListApi = (data: {
  page: number
  pageSize: number
  orderState: number
}) => {
  return http<OrderListResult>({
    url: '/member/order',
    method: 'GET',
    data,
  })
}
